package cn.lixin.hrm.web.controller;

import cn.lixin.hrm.dto.SMSCodeDto;
import cn.lixin.hrm.service.IVerifyCodeService;
import cn.lixin.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 图形验证码
     * @param key
     * @return
     * @throws IOException
     */
    @GetMapping("/imageCode/{key}")
    public AjaxResult imageCode(@PathVariable("key") String key) throws IOException {
        String imageCode = verifyCodeService.imageCode(key);
        return new AjaxResult().setResultObj(imageCode);
    }

    /**
     * 短信验证码
     * @param dto
     * @return
     */
    @PostMapping("/sendSmsCode")
        public AjaxResult sendSMSCode(@RequestBody @Valid SMSCodeDto dto) {
            verifyCodeService.sendSMSCode(dto);
            return AjaxResult.me();
        }
}
